import logging
from datetime import datetime

from sqlalchemy import *

from clutch.globals import G
from environ import metadata, AppTable, AppForeignKey, AppColumn

log = logging.getLogger('identity.model.tables')

user = AppTable(
    'user', metadata,
    AppColumn('id', Integer, primary_key=True),
    AppColumn('email_address', Unicode(255), unique=True),
    AppColumn('cell_phone', Unicode(255)),
    AppColumn('display_name', Unicode(255)),
    AppColumn('password', String(40)),
    AppColumn('created', DateTime, default=datetime.now))

group = AppTable(
    'group', metadata,
    AppColumn('id', Integer, primary_key=True),
    AppColumn('name', String(255), unique=True),
    AppColumn('display_name', Unicode(255)))

permission = AppTable(
    'permission', metadata,
    AppColumn('id', Integer, primary_key=True),
    AppColumn('name', String(255), unique=True),
    AppColumn('display_name', Unicode(255)))

user_group = AppTable(
    'user_group', metadata,
    AppColumn('user_id', AppForeignKey('user.id')),
    AppColumn('group_id', AppForeignKey('group.id')))

group_permission = AppTable(
    'group_permission', metadata,
    AppColumn('group_id', AppForeignKey('group.id')),
    AppColumn('permission_id', AppForeignKey('permission.id')))

